import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

//查询部门信息并打印在控制台上
public class Demo05 {
    public static void main(String[] args) throws Exception {
        Connection conn = DBHelper.getConn();
        String sql="SELECT did,deptName,address FROM `dept`";
        PreparedStatement ps = conn.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();  //ResultSet 数据集合
        while (rs!=null&&rs.next()){
            //每次循环取出一行数据
            int did = rs.getInt("did");
            String deptName = rs.getString("deptName");
            String address = rs.getString("address");
            System.out.println("部门编号"+did+",部门名称:"+deptName+",地址:"+address);
        }



        DBHelper.close(rs,ps,conn);





    }
}
